/*
 * Copyright 2018-2019 KunMinX
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain menu_text_color copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.wanchuang.hepos.bridge.request;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.wanchuang.hepos.bridge.data.repository.HttpRequestManager;
import com.wanchuang.hepos.proto.Index;
import com.wanchuang.hepos.proto.MemberCoupon;
import com.wanchuang.hepos.proto.MemberOuterClass;

import java.util.List;

/**
 * 音乐资源  RequestViewModel
 * <p>
 * TODO tip：RequestViewModel 通常按业务划分
 * 一个项目中通常存在多个 RequestViewModel
 * 对 Jetpack ViewModel 的知识点感兴趣可详见 https://xiaozhuanlan.com/topic/6257931840
 * <p>
 * Create by KunMinX at 19/10/29
 */
public class MineRequestViewModel extends ViewModel {

    private MutableLiveData<String> errorString;  // 错误信息的返回
    private MutableLiveData<String> resultString;  // 成功信息的返回
    private MutableLiveData<Boolean> couponState;  // 成功信息的返回
    private MutableLiveData<Boolean> changeSettingState;  // 成功信息的返回
    private MutableLiveData<String> upAgentState;  // 成功信息的返回
    private MutableLiveData<String> allTitle;  // 标题
    private MutableLiveData<String> allContent; // 内容
    private MutableLiveData<MemberOuterClass.Member> member;  //  个人信息
    private MutableLiveData<Index.get_kfu_info> kfuBean;  //  获取客服
    private MutableLiveData<List<MemberCoupon.CouponInfo>> coupon_one;  //  未使用
    private MutableLiveData<List<MemberCoupon.CouponInfo>> coupon_two;  //  已使用

    public MutableLiveData<MemberOuterClass.Member> getMember()
    {
        if (member == null) {
            member = new MutableLiveData<>();
        }
        return member;
    }

    public MutableLiveData<String> getUpAgentState()
    {
        if (upAgentState == null) {
            upAgentState = new MutableLiveData<>();
        }
        return upAgentState;
    }

    public MutableLiveData<String> getAllTitle()
    {
        if (allTitle == null) {
            allTitle = new MutableLiveData<>();
        }
        return allTitle;
    }


    public MutableLiveData<String> getAllContent()
    {
        if (allContent == null) {
            allContent = new MutableLiveData<>();
        }
        return allContent;
    }


    public MutableLiveData<Boolean> getCouponState()
    {
        if (couponState == null) {
            couponState = new MutableLiveData<>();
        }
        return couponState;
    }

    public MutableLiveData<Boolean> getChangeSettingState()
    {
        if (changeSettingState == null) {
            changeSettingState = new MutableLiveData<>();
        }
        return changeSettingState;
    }



    public MutableLiveData<Index.get_kfu_info> getKfuBean() {
        if (kfuBean == null) {
            kfuBean = new MutableLiveData<>();
        }
        return kfuBean;
    }






    public MutableLiveData<String> getErrorString() {
        if (errorString == null) {
            errorString = new MutableLiveData<>();
        }
        return errorString;
    }


    public MutableLiveData<String> getResultString() {
        if (resultString == null) {
            resultString = new MutableLiveData<>();
        }
        return resultString;
    }



    public MutableLiveData<List<MemberCoupon.CouponInfo>> get_coupon_list_one() {
        if (coupon_one == null) {
            coupon_one = new MutableLiveData<>();
        }
        return coupon_one;
    }

    public MutableLiveData<List<MemberCoupon.CouponInfo>> get_coupon_list_two() {
        if (coupon_two == null) {
            coupon_two = new MutableLiveData<>();
        }
        return coupon_two;
    }


    public void getMemberInfo() {
        HttpRequestManager.getInstance().get_member_info(getMember(),getErrorString());
    }





    public void feedback_add(String feedback) {
        HttpRequestManager.getInstance().feedback_add(getResultString(),getErrorString(),feedback);
    }

    public void get_kfu_info() {
        HttpRequestManager.getInstance().get_kfu_info(getKfuBean(),getErrorString());
    }

    public void get_coupon_list(String type,int page) {
        if (type.equals("1"))
        {
            HttpRequestManager.getInstance().get_coupon_list(get_coupon_list_one(),getErrorString(),type,page);
        }else
        {
            HttpRequestManager.getInstance().get_coupon_list(get_coupon_list_two(),getErrorString(),type,page);
        }
    }

    public void set_coupon_state(  String state) {
        HttpRequestManager.getInstance().set_coupon_state(getErrorString(), getCouponState(),state);
    }


    public void set_trade_state( String state) {
        HttpRequestManager.getInstance().set_trade_state(getErrorString(),getChangeSettingState(), state);
    }



    public void get_coupon_state( ) {
        HttpRequestManager.getInstance().get_coupon_state(getCouponState(),getAllTitle(),getAllContent());
    }


    public void get_trade_state( ) {
        HttpRequestManager.getInstance().get_trade_state(getChangeSettingState(),getAllTitle(),getAllContent());
    }


    public void get_upgrade_agent( ) {
        HttpRequestManager.getInstance().get_upgrade_agent(getErrorString(),getUpAgentState(),getAllTitle(),getAllContent());
    }

    public void set_upgrade_agent(String name,String phone ) {
        HttpRequestManager.getInstance().set_upgrade_agent(getErrorString(),getUpAgentState(),getAllTitle(),getAllContent(),name,phone);
    }



}
